package com.example.day7;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

import com.example.day7.View.FragmentA;
import com.example.day7.View.FragmentB;
import com.example.day7.View.VpAdapter;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private Toolbar main_toolbar;
    private ViewPager main_vp;
    private TabLayout main_tab;
    private ArrayList<Fragment> list;
    private ArrayList<String> title;
    private VpAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

    }

    private void initView() {
        main_toolbar = (Toolbar) findViewById(R.id.main_toolbar);
        main_vp = (ViewPager) findViewById(R.id.main_vp);
        main_tab = (TabLayout) findViewById(R.id.main_tab);

        main_tab.setupWithViewPager(main_vp);

        list = new ArrayList<>();
        list.add(new FragmentA());
        list.add(new FragmentB());

        title = new ArrayList<>();
        title.add("首页");
        title.add("网页");

        adapter = new VpAdapter(getSupportFragmentManager(), list, title);
        main_vp.setAdapter(adapter);


    }
}
